//
//  CLNavigationViewController.swift
//  SinaCaoliang
//
//  Created by 曹亮 on 16/10/22.
//  Copyright © 2016年 曹亮. All rights reserved.
//

import UIKit

class CLNavigationViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        ///开启屏幕左侧滑动pop控制器
        interactivePopGestureRecognizer?.delegate = self
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        var titleTemp  = String()

        if childViewControllers.count > 0 {
            titleTemp = "返回"
            if navigationController?.childViewControllers.count == 1 {

                titleTemp = navigationController?.navigationItem.title ?? ""
            }


            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(setImgName: "navigationbar_back_withtext", title: titleTemp, titleColor: UIColor.darkGray, target: self, action: #selector(backBtnClick))
        }
        super.pushViewController(viewController, animated: true)
    }

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        // 如果. count == 1 就代表你已经到首页了 不能在滑动了
        return childViewControllers.count != 1
    }


    /// 返回按钮方法
    @objc func backBtnClick() -> Void {

        popViewController(animated: true)

    }
}
